   package com.qfedu.product.service.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.naming.spi.DirStateFactory.Result;

import com.qfedu.product.dao.productDAO;
import com.qfedu.product.dao.impl.productDaoimpl;
import com.qfedu.product.po.Product;
import com.qfedu.product.service.productService;
import com.qfedu.user.util.DBUtil;


public class productServiceimpl implements productService {
	DBUtil dBUtil=new DBUtil();
	productDAO productDAO = new productDaoimpl();
	
	
	@Override
	public List<Product> selectSellOne(Object[] objects) {
		return productDAO.doSelectSellOne(objects);
		//return productDAO.selectSellOne;
	}


	@Override
	 public  boolean doEnter(Object[] objects)   {		
		String sql="select * from enter_warehouse where PRODUCTION_ID='"+objects[0]+"'";
        ResultSet rs=dBUtil.executeQuery(sql, null);
      try {
		if (rs.next()) {
			   
			 String sql1="updata enter_warehouse set PRODUCTION_NUM='"+objects[1]+rs.getInt(7)+"'";
			 if(dBUtil.executeUpdate(sql1, null)!=-1) {
				objects[1]=(int)objects[1]+rs.getInt(7);  
				return true;
			 }
		    }
		  
		  else {
			String sql2="insert into enter_warehouse (PRODUCTION_ID,PRODUCTION_NUM,PRODUCTION_NAME,PRODUCTION_COST,PRODUCTION_TYPE) values(?,?,?,?,?) ";
			if (dBUtil.executeUpdate(sql2, objects)!=-1) {
				return true;
			}		
			
		}
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
                        return true;
	}


	@Override
	public Object[] doOuter(Object[] objects) {
		// TODO Auto-generated method stub
		return objects;
	}
	
	
	public Product add(String a) throws SQLException {
		Product product=null;
		String sql="select * from enter_warehouse where PRODUCTION_ID='"+a+"'";
	ResultSet set=	dBUtil.executeQuery(sql, null);
	if(set.next()) {
		 product=new Product(set.getString(3),set.getInt(7),set.getString(4),set.getInt(5),set.getString(6));
	}
		
		
		
		return product;
	}



}
